package com.hotel.controller;

import com.hotel.entity.Guest;
import com.hotel.service.GuestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/api")
public class GuestController {
    @Autowired
    GuestService guestService;
    //查
    @GetMapping("/admin/guests")
    public List<Guest> searchGuests(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String id_card) {
        return guestService.SearchGuest(name, id_card);
    }
    //增
    @PostMapping("/admin/guests")
    void insertGuest(@RequestBody Guest guest) {
        guestService.addGuest(guest);
    }
    //改
    @PutMapping("/admin/guests/{id}")
    void updateGuest(@PathVariable int id, @RequestBody Guest guest) {
        guestService.update(id, guest);
    }
    //删
    @DeleteMapping("/admin/guests/{id}")
    void deleteGuest(@PathVariable int id) {
        guestService.delete(id);
    }

    @GetMapping("/client/guests/{id_card}")
    public Guest findByIdCard(@PathVariable String id_card)
    {
        return guestService.findByIdCard(id_card);
    }

}
